package com.zenithmind.disk.controller;


import com.zenithmind.common.annotation.Log;
import com.zenithmind.common.constant.OperationTypeEnum;
import com.zenithmind.disk.pojo.domain.RecycleBin;
import com.zenithmind.disk.pojo.query.RecycleBinQuery;
import com.zenithmind.disk.pojo.vo.RecycleBinVO;
import com.zenithmind.disk.service.RecycleBinService;
import com.zenithmind.common.result.PageResult;
import com.zenithmind.common.result.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/api/zenithMind/recycleBin")
@Tag(name = "回收站管理")
public class RecycleBinController {
    @Autowired
    private RecycleBinService recycleBinService;

    @Log(description = "列出回收站文件", operationType = OperationTypeEnum.QUERY)
    @Operation(summary = "列出回收站文件")
    @GetMapping("/listRecycleBin")
    public Result<List<RecycleBinVO>> listRecycleBin() {
        List<RecycleBinVO> recycleBinVOS = recycleBinService.listRecycleBin();
        return Result.success(recycleBinVOS);
    }

    @Log(description = "恢复文件", operationType = OperationTypeEnum.UPDATE)
    @Operation(summary = "恢复文件")
    @GetMapping("/restoreFile")
    public Result<Boolean> restoreFile(String fileId, String userId) {
        boolean b = recycleBinService.restoreFile(fileId, userId);
        return Result.success(b);
    }

    @Log(description = "彻底删除文件", operationType = OperationTypeEnum.DELETE)
    @Operation(summary = "彻底删除文件")
    @GetMapping("/deleteForever")
    public Result<Boolean> deleteForever(String fileId, String userId) {
        boolean b = recycleBinService.deleteForever(fileId, userId);
        return Result.success(b);
    }

    @Log(description = "清空回收站", operationType = OperationTypeEnum.DELETE)
    @Operation(summary = "清空回收站")
    @GetMapping("/clearRecycleBin")
    public Result<Boolean> clearRecycleBin() {
        boolean b = recycleBinService.clearRecycleBin();
        return Result.success(b);
    }

    @Log(description = "分页查询回收站文件", operationType = OperationTypeEnum.QUERY)
    @Operation(summary = "分页查询回收站文件")
    @GetMapping("/recycleBinPage")
    public Result<PageResult<RecycleBinVO>> recycleBinPage(RecycleBinQuery recycleBinQuery) {
        log.info("分页查询回收站文件：{}", recycleBinQuery);
        PageResult<RecycleBinVO> recycleBinVOPageResult = recycleBinService.recycleBinPage(recycleBinQuery);
        return Result.success(recycleBinVOPageResult);
    }

    @Log(description = "批量删除回收站文件", operationType = OperationTypeEnum.DELETE)
    @Operation(summary = "批量删除回收站文件-管理员")
    @DeleteMapping("/deleteBatchRecycleBin")
    public Result<Boolean> deleteBatchRecycleBin(@RequestBody List<String> ids) {
        log.info("批量删除回收站文件：{}", ids);
        boolean result = recycleBinService.deleteBatchRecycleBin(ids);
        return Result.success(result);
    }

    @Log(description = "添加或修改回收站记录", operationType = OperationTypeEnum.UPDATE)
    @Operation(summary = "添加或修改回收站记录-管理员")
    @PostMapping("/addOrUpdateRecycleBin")
    public Result<RecycleBinVO> addOrUpdateRecycleBin(@RequestBody RecycleBin recycleBin) {
        log.info("添加或修改回收站记录：{}", recycleBin);
        RecycleBinVO recycleBinVO = recycleBinService.addOrUpdateRecycleBinByAdmin(recycleBin);
        return Result.success(recycleBinVO);
    }
}
